package com.zretc.service.impl;

import com.zretc.dao.AddressMapper;
import com.zretc.dao.HouseMapper;
import com.zretc.entity.House;
import com.zretc.entity.HouseManager;
import com.zretc.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;
import java.util.Map;

/**
 * @author: bLUeSuMMerDreamer
 * @createTime: 2020-07-25 02:47
 */
@Service
public class HouseServiceImpl implements HouseService {
    @Autowired
    private HouseMapper houseMapper;
    @Autowired
    private AddressMapper addressMapper;
    @Autowired
    JedisPool jedisPool;

    /**
     * 添加仓库
     *
     * @param house
     * @author: bLUeSuMMerDreamer
     * @date: 2020/7/25 4:45
     * @return: java.lang.Boolean
     */
    @Override
    @Transactional
    public Boolean addHouse(House house) {
        Jedis jedis = jedisPool.getResource();
        if (addressMapper.insertAddress(house.getAddress()) == 1) {
            return houseMapper.insertHouse(house) == 1;
        } else {
            return false;
        }
    }

    /**
     * 根据参数获取仓库列表
     *
     * @param params
     * @author: bLUeSuMMerDreamer
     * @date: 2020/7/25 4:45
     * @return: java.util.List<com.zretc.entity.House>
     */
    @Override
    public List<House> getHousesByParams(Map<String, Object> params) {
        return houseMapper.findHousesByParams(params);
    }
}
